class MedianFinder {
public:
    MedianFinder() {
        
    }
    
    void addNum(int num) {
        minHeap.push(num);
        if(minHeap.size()&&maxHeap.size()&&minHeap.top()<maxHeap.top())
        {
            maxHeap.push(minHeap.top());
            minHeap.pop();
        }
        if(minHeap.size()+1<maxHeap.size())
        {
            minHeap.push(maxHeap.top());
            maxHeap.pop();
        }
        if(maxHeap.size()+1<minHeap.size())
        {
            maxHeap.push(minHeap.top());
            minHeap.pop();
        }
    }
    
    double findMedian() {
        if(minHeap.size()>maxHeap.size())
            return minHeap.top();
        else if(maxHeap.size()>minHeap.size())
            return maxHeap.top();
        else
            return (maxHeap.top()+minHeap.top())/2.0;

    }
    priority_queue<int,vector<int>,less<int>> maxHeap;
    priority_queue<int,vector<int>,greater<int>> minHeap;
};

/**
 * Your MedianFinder object will be instantiated and called as such:
 * MedianFinder* obj = new MedianFinder();
 * obj->addNum(num);
 * double param_2 = obj->findMedian();
 */
